<?php

namespace app\admin\controller;

use app\model\Root;
class Login {
	function index() {
		$input = input('post.');
		if (empty($input['account']) || empty($input['password'])){
			return json(['status'=>false,'msg'=>'账号或密码不能为空']);
		}
		$root=Root::where(['account'=>$input['account']])->select();
		if (empty($root['0'])){
			return json(['status' => false, 'msg' => '账号不存在']);
		}
		if ($root['0']['password']!=$input['password']){
			return json(['status'=>false,'msg'=>'密码错误']);
		}
		$token=JwtUtil::encode($input);
		\session('identity',$root['0']['identity']);
		return json(['status'=>true,'token'=>$token,'type'=>true,'user'=>$root]);
	}
}